package com.sss.ordermodel.controller;


import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.sss.common.responseutil.Result;
import com.sss.ordermodel.entities.OrderSss;
import com.sss.ordermodel.entities.OrdersDetail;
import com.sss.ordermodel.service.IOrderSssService;
import com.sss.ordermodel.vo.OrderVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author sss
 * @since 2020-04-06
 */
@RestController
@RequestMapping("/order")
@DefaultProperties(defaultFallback = "globalFallbackMethod")//全局服务降级defaultFallback 代表回调方法
public class OrderSssController {

    @Autowired
    private IOrderSssService orderSssService;

    /**
     * 添加订单
     * @param orderVO
     * @return com.sss.common.responseutil.Result<java.lang.Integer>
     * @author SSS
    **/
    @PostMapping("/add")
    @HystrixCommand
    public Result saveOrder(OrderVO orderVO){
        Integer id = orderSssService.saveOrder(orderVO);
        return Result.succes(id);
    }

    /**
     * 订单列表
     * @param
     * @return com.sss.common.responseutil.Result<java.util.List<com.sss.ordermodel.entities.OrderSss>>
     * @author SSS
    **/
    @GetMapping("/list")
    public Result orderList(){
        List<OrderSss> list = orderSssService.list();
        return Result.succes(list);
    }

   /**
    * 订单详情
    * @param orderId  订单ID
    * @return com.sss.common.responseutil.Result<java.util.List<com.sss.ordermodel.entities.OrderSss>>
    * @author WYY-SSS
   **/
    @GetMapping("/{orderId}")
    public Result getOrderById(@PathVariable Integer orderId){
        return Result.succes(orderSssService.getOrderById(orderId));
    }

    //降级处理方法返回值和参数必须跟出错的方法一致才能生效
    public Result globalFallbackMethod(){

        return Result.serverBusy();
    }
}

